define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Customqq, GoDialog, GoPage, $window) {
		//画面加载
		//动态设置高度
		//			$scope.init_data();
		var lan = 0; //这是状态栏，只有ios的APP才有
		var tab = 0;
		var bars = document.getElementById("nav-bar-title");
		var bar = ((bars != undefined) ? 44 : 0);
		if(window.cordova && window.cordova.plugins && ionic.Platform.isIOS()) { lan = 20; }
		//整体高度
		var all = $window.innerHeight;
		var custom_top = document.getElementById("custom-top").clientHeight;
		$scope.custom_Obj = { //滚动条可视范围
			"height": all - lan - bar - tab - custom_top + "px"
		};
		$scope.$on('$ionicView.afterEnter', function() {
//			console.log($scope);
			$scope.init_data();
		}, false);
		$scope.init_data = function() {
			Customqq.contact_show(function(data) {
				$scope.datas = data;
				console.log(data);
			})
		}
//		$scope.init_data();
		$scope.delete_contact = function(id) {
			Customqq.contact_delete(id, function(data) {
				if(data.success == true) {
					GoDialog.toast("删除成功");
					$scope.init_data();
				} else {
					GoDialog.toast(data.msg);
				}
			})
		}
		$scope.setdefault_contact = function(id) {
			Customqq.contact_setdefault(id, function(data) {
				if(data.success == true) {
					GoDialog.toast("设置成功");
					$scope.init_data();
				} else {
					GoDialog.toast(data.msg);
				}
			})
		}
		//页面跳转
		$scope.onshow_customqqAdd = function(id,type) {
			GoPage.go_states("customqqAdd", { "id": id,"type":type });
		}
		//		$scope.init_data();
	}

	controller.$inject = ['$scope', 'Customqq', 'GoDialog', 'GoPage', '$window'];

	return app.registerController("customqqctrl",controller);
});